<template>
  <div>
    <div class="dashboard-container">
      

      <div class="big-back-box">
        <div class="top" style="margin-bottom: 20px">抢单自荐</div>
        <!-- 当前求助id编号 -->
        <div style="width: 600px; margin: 0 auto">
          <el-form ref="form" :model="helpForm" label-width="100px">
            <el-form-item label="求助id" style="width: 1000px">
              <span style="margin-left: 10px; font-size: 15px"
                ><b>{{ this.helpForm.id }}</b></span
              >
            </el-form-item>
          </el-form>
        </div>
        <!-- 卡片 -->
        <div style="width: 600px; margin: 0 auto">
          <el-form ref="form" :model="form" label-width="80px">
            <!-- 服务价格 -->
            <el-form-item label="服务价格">
              <el-input v-model="form.money"></el-input>
            </el-form-item>
            <!-- 内容描述 -->
            <el-form-item label="自荐描述">
              <el-input
                type="textarea"
                v-model="form.selfRecommendationDescription"
                rows="5"
                :disabled="false"
              ></el-input>
            </el-form-item>
            <!-- 按钮 -->
            <el-form-item>
              <router-link to="/lawHelp/lawyerHelpList">
                <el-button type="primary" @click="submitSelfRecommend"
                  >抢单</el-button
                >
              </router-link>
              <router-link to="/lawHelp/lawyerHelpList">
                <el-button style="margin-left: 20px">返回</el-button>
              </router-link>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 获取当前登录账户信息
import { returnUserInformation } from "@/api/user.js";

// 新增抢单自荐
import { addOrderGrabbing } from "@/api/lawHelp.js";

export default {
  data() {
    return {
      size: "",
      // “自荐”数据
      form: {
        id: 0,
        legalRecourseId: 0,
        money: 0,
        orderGrabbingTime: "",
        selfRecommendationDescription: "",
        serviceId: 0,
      },
      // 接收“求助”数据
      helpForm: {},
    };
  },
  // 初始化
  mounted() {
    // 接收传参
    console.log("this.$route.query" + this.$route.query);
    this.helpForm = this.$route.query;
    console.log("求助id this.helpForm.id: " + this.helpForm.id);
    console.log("求助标题 this.helpForm.title: " + this.helpForm.title);
  },
  methods: {
    // 获取当前时间
    getOrderGrabbingTime() {
      var standardDate = new Date();
      console.log(standardDate); //Wed Aug 21 2019 10:00:58 GMT+0800 (中国标准时间)
      this.form.orderGrabbingTime =
        standardDate.getFullYear() +
        "-" +
        (standardDate.getMonth() + 1) +
        "-" +
        standardDate.getDate() +
        " " +
        standardDate.getHours() +
        ":" +
        standardDate.getMinutes() +
        ":" +
        standardDate.getSeconds();
      console.log("this.form.orderGrabbingTime:" + this.form.orderGrabbingTime); //2019-8-20 03:22:30
    },
    // 提交抢单自荐
    submitSelfRecommend() {
      console.log("提交抢单自荐 submitSelfRecommend()");
      // 先执行获取当前时间函数
      this.getOrderGrabbingTime();
      // 执行获取当前登录用户接口，提取id
      returnUserInformation().then((resp) => {
        console.log(
          "returnUserInformation().then(resp) 执行获取当前登录用户接口，提取id"
        );
        console.log("resp.data.user.id: " + resp.data.user.id);
        this.form.serviceId = resp.data.user.id;
        console.log("this.form.serviceId: " + this.form.serviceId);
        console.log("let data前 this.helpForm.id:" + this.helpForm.id); //为什么这里不能执行？？？
        // 【放到then里异步执行！因为需要上面接口返回的当前登录id】
        let data = {
            id: 0,
            legalRecourseId: this.helpForm.id,
            money: this.form.money,
            orderGrabbingTime: this.form.orderGrabbingTime,
            selfRecommendationDescription:
              this.form.selfRecommendationDescription,
            serviceId: this.form.serviceId,
          };
        console.log("data");
        console.log("data.serviceId: " + data.serviceId);
        // 执行接口提交自荐
        addOrderGrabbing(data).then((resp) => {
          console.log("新增抢单自荐 addOrderGrabbing(data)");
          console.log("resp: " + resp);
          console.log("resp.data.message: " + resp.data.message);
          console.log("resp.data.error: " + resp.data.error);
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
// 页头LOGO
.top {
  height: 50px;
  font-size: 30px;
  text-align: center;
  line-height: 50px;
}

// 大盒子
.big-back-box {
  width: 1080px;
  margin: 0 auto;
}

// 原框架自带
.dashboard {
  &-container {
    margin-top: 30px;
    // margin-left: 30px;
    // margin-right: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

// 页脚
.footer {
  height: 300px;
  background-color: blue;
}
.footer-back-box {
  width: 1080px;
  margin-left: 45px;
}
.footer-title {
  height: 30px;
  line-height: 40px;
  padding-left: 10px;
}
.footer-link-card {
  width: 200px;
  background-color: orange;
  margin-left: 10px;
}

// 模板-卡片
.text {
  font-size: 14px;
}
.item {
  padding: 18px 0;
}
.box-card {
  width: 480px;
}
</style>